package com.qxsx.midi.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.qxsx.midi.R;
import com.qxsx.midi.model.ReceivingAddress;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Zrj on 2015/9/14.
 */
public class RexeivingAddressAdapter extends BaseAdapter {

    private List<ReceivingAddress> list = new ArrayList<>();
    private LayoutInflater inflater;
    private Context context;

    public RexeivingAddressAdapter(Context context, List<ReceivingAddress> list) {
        this.context = context;
        this.list = list;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;

        if (convertView == null) {

            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_list_add_address, null);
            holder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            holder.tv_address = (TextView) convertView.findViewById(R.id.tv_address);
            holder.tv_phone = (TextView) convertView.findViewById(R.id.tv_phone);
            holder.tv_moren = (TextView) convertView.findViewById(R.id.tv_moren);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        final ReceivingAddress receivingAddress = list.get(position);
        holder.tv_name.setText(receivingAddress.getName());


        return convertView;
    }


    class ViewHolder {
        TextView tv_moren;
        TextView tv_name;
        TextView tv_phone;
        TextView tv_address;
    }
}
